package View;

import Shared.Server;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 *
 * @author CCD gruppe 2
 */
public class ActivityInfoPanel extends javax.swing.JPanel {

    private javax.swing.JLabel boundToSessionLabel;
    private javax.swing.JComboBox statusDropDown;

    private javax.swing.JComboBox responsibleDropDown;
    private javax.swing.JLabel responsibleLabel;
    private javax.swing.JLabel startDateLabel;
    private javax.swing.JTextField startDateTextField;
    private javax.swing.JLabel statusLabel;
    private javax.swing.JLabel strekLabel;

    private javax.swing.JCheckBox actionListCheckBox;
    private javax.swing.JLabel activityDescLabel;
    private javax.swing.JTextArea activityDescTextArea;
    private javax.swing.JLabel activityGoalsLabel;
    private javax.swing.JTextArea activityGoalsTextArea;
    private javax.swing.JLabel activityNameLabel;
    private javax.swing.JLabel activityPlaceLabel;
    private javax.swing.JTextField activityPlaceTextField;
    private javax.swing.JComboBox boundToSessionDropDown;
    private javax.swing.JButton saveActivityButton;
    private javax.swing.JTextField endDateTextField;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextField activityNameTextField;


    DefaultComboBoxModel activityResponsibleModel;
    DefaultComboBoxModel activityStatusModel;
    DefaultComboBoxModel boundToSessionModel;

    public ActivityInfoPanel() {
        initComponents();
    }

    private void initComponents() {

        activityNameLabel = new javax.swing.JLabel();
        activityGoalsLabel = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        activityGoalsTextArea = new javax.swing.JTextArea();
        activityPlaceLabel = new javax.swing.JLabel();
        saveActivityButton = new javax.swing.JButton();
        activityPlaceTextField = new javax.swing.JTextField();
        startDateLabel = new javax.swing.JLabel();
        startDateTextField = new javax.swing.JTextField();
        strekLabel = new javax.swing.JLabel();
        endDateTextField = new javax.swing.JTextField();
        responsibleLabel = new javax.swing.JLabel();
        statusLabel = new javax.swing.JLabel();
        activityDescLabel = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        activityDescTextArea = new javax.swing.JTextArea();
        actionListCheckBox = new javax.swing.JCheckBox();
        responsibleDropDown = new javax.swing.JComboBox();
        statusDropDown = new javax.swing.JComboBox();
        boundToSessionLabel = new javax.swing.JLabel();
        boundToSessionDropDown = new javax.swing.JComboBox();
        jSeparator2 = new javax.swing.JSeparator();
        activityNameTextField = new JTextField();

        activityStatusModel = new DefaultComboBoxModel();
        activityResponsibleModel = new DefaultComboBoxModel();
        boundToSessionModel = new DefaultComboBoxModel();

        activityNameLabel.setFont(new java.awt.Font("Lucida Grande", 1, 13)); // NOI18N
        activityNameLabel.setText("Navn på aktivitet:");
        boundToSessionLabel.setFont(new java.awt.Font("Lucida Grande", 1, 13)); // NOI18N
        boundToSessionLabel.setText("Knyttes til sesjon:");


        activityResponsibleModel.addElement("Velg ansvarlig");
        responsibleDropDown.setModel(activityResponsibleModel);

        activityStatusModel.addElement("Registrert");
        activityStatusModel.addElement("Åpen");
        activityStatusModel.addElement("Stengt");
        statusDropDown.setModel(activityStatusModel);

        boundToSessionModel.addElement("Ingen tilknytning");
        boundToSessionDropDown.setModel(boundToSessionModel);
        setBorder(javax.swing.BorderFactory.createTitledBorder("Aktivitet X"));


        activityGoalsLabel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        activityGoalsLabel.setText("Mål:");


        activityPlaceLabel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        activityPlaceLabel.setText("Sted:");

        saveActivityButton.setText("Lagre");

        startDateLabel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        startDateLabel.setText("Dato:");


        strekLabel.setText("-");

        responsibleLabel.setFont(new java.awt.Font("Tahoma", 1, 12));
        responsibleLabel.setText("Ansvarlig:");

        statusLabel.setFont(new java.awt.Font("Tahoma", 1, 12));
        statusLabel.setText("Status:");

        activityDescLabel.setFont(new java.awt.Font("Tahoma", 1, 12));
        activityDescLabel.setText("Beskrivelse:");

        actionListCheckBox.setText("På aksjonsliste");

        activityGoalsTextArea.setColumns(20);
        activityGoalsTextArea.setLineWrap(true);
        activityGoalsTextArea.setRows(5);
        activityGoalsTextArea.setWrapStyleWord(true);
        jScrollPane5.setViewportView(activityGoalsTextArea);

        activityDescTextArea.setColumns(20);
        activityDescTextArea.setLineWrap(true);
        activityDescTextArea.setRows(5);
        activityDescTextArea.setWrapStyleWord(true);
        jScrollPane6.setViewportView(activityDescTextArea);
        jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);

        org.jdesktop.layout.GroupLayout activityInfoPanelLayout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(activityInfoPanelLayout);
        activityInfoPanelLayout.setHorizontalGroup(
            activityInfoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(activityInfoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(activityInfoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(activityInfoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                        .add(activityNameLabel)
                        .add(statusLabel)
                        .add(responsibleLabel)
                        .add(boundToSessionLabel)
                        .add(saveActivityButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 158, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(boundToSessionDropDown, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(statusDropDown, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(responsibleDropDown, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(activityNameTextField)
                        .add(jScrollPane6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 315, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(activityDescLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(activityInfoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(activityGoalsLabel)
                    .add(actionListCheckBox)
                    .add(activityPlaceLabel)
                    .add(activityInfoPanelLayout.createSequentialGroup()
                        .add(startDateTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 145, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(strekLabel)
                        .add(18, 18, 18)
                        .add(endDateTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))
                    .add(startDateLabel)
                    .add(activityPlaceTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)
                    .add(jScrollPane5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE))
                .addContainerGap())
        );
        activityInfoPanelLayout.setVerticalGroup(
            activityInfoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, activityInfoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(activityInfoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jSeparator2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 370, Short.MAX_VALUE)
                    .add(activityInfoPanelLayout.createSequentialGroup()
                        .add(activityInfoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(activityInfoPanelLayout.createSequentialGroup()
                                .add(activityNameLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(activityNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(6, 6, 6)
                                .add(boundToSessionLabel))
                            .add(activityInfoPanelLayout.createSequentialGroup()
                                .add(startDateLabel)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(activityInfoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(startDateTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(endDateTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(strekLabel))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(activityPlaceLabel)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(activityInfoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(boundToSessionDropDown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(activityPlaceTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(activityInfoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(activityInfoPanelLayout.createSequentialGroup()
                                .add(8, 8, 8)
                                .add(statusLabel)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(statusDropDown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(activityInfoPanelLayout.createSequentialGroup()
                                .add(29, 29, 29)
                                .add(actionListCheckBox)))
                        .add(9, 9, 9)
                        .add(activityInfoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(activityInfoPanelLayout.createSequentialGroup()
                                .add(responsibleLabel)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(responsibleDropDown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(activityDescLabel))
                            .add(activityGoalsLabel))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(activityInfoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jScrollPane5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                            .add(jScrollPane6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE))))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(saveActivityButton)
                .addContainerGap())
        );
    }

    /**
     * A method that shows the activity info.
     * @param activityName
     * @param startDate
     * @param endDate
     * @param status
     * @param description
     * @param goals
     * @param place
     * @param responsible
     * @param onActionList
     */
    public void showActivityInfo(String activityName, String startDate, String endDate, String status, String description,
            String goals, String place, String responsible, boolean onActionList) {

        setBorder(javax.swing.BorderFactory.createTitledBorder(activityName));
        boundToSessionDropDown.setEnabled(false);
        activityNameTextField.setText(activityName);
        startDateTextField.setText(startDate);
        startDateTextField.setFocusable(false);
        endDateTextField.setText(endDate);
        endDateTextField.setFocusable(false);
        statusDropDown.setSelectedItem(status);
        statusDropDown.setEnabled(false);
        activityDescTextArea.setText(description);
        activityDescTextArea.setFocusable(false);
        activityGoalsTextArea.setText(goals);
        activityGoalsTextArea.setFocusable(false);
        activityPlaceTextField.setText(place);
        activityPlaceTextField.setFocusable(false);
        actionListCheckBox.setSelected(onActionList);
        actionListCheckBox.setEnabled(false);
        responsibleDropDown.setEnabled(false);
        activityResponsibleModel.removeAllElements();
        activityResponsibleModel.addElement(responsible);
        saveActivityButton.setText("Rediger");

        setVisible(true);
    }

    /**
     * A method that hides the activity info.
     */
    public void hideActivityInfo() {
        activityNameTextField.setText("");
        startDateTextField.setText("");
        endDateTextField.setText("");
        statusDropDown.setFocusable(false);
        responsibleDropDown.setFocusable(false);
        activityDescTextArea.setText("");
        activityGoalsTextArea.setText("");
        activityPlaceTextField.setText("");
        responsibleDropDown.setFocusable(false);
        setVisible(false);
    }

    /**
     * A method that clears the input.
     */
    public void clearInput(){
        setBorder(javax.swing.BorderFactory.createTitledBorder("Ny aktivitet"));
        boundToSessionModel.removeAllElements();
        boundToSessionModel.addElement("Ingen tilknytning");
        statusDropDown.setSelectedIndex(0);
        activityNameTextField.setText("");
        startDateTextField.setText("");
        startDateTextField.setFocusable(true);
        strekLabel.setVisible(true);
        endDateTextField.setText("");
        endDateTextField.setFocusable(true);
        endDateTextField.setVisible(true);
        activityDescTextArea.setText("");
        activityGoalsTextArea.setText("");
        activityPlaceTextField.setText("");
        activityResponsibleModel.removeAllElements();
        activityResponsibleModel.addElement("Velg ansvarlig");
        responsibleDropDown.setSelectedIndex(0);
        actionListCheckBox.setSelected(false);
        statusDropDown.setEnabled(true);
        responsibleDropDown.setEnabled(true);
        activityDescTextArea.setFocusable(true);
        activityGoalsTextArea.setFocusable(true);
        actionListCheckBox.setEnabled(true);
        activityPlaceTextField.setFocusable(true);
        boundToSessionDropDown.setEnabled(true);
        saveActivityButton.setText("Opprett");

    }

    public void setBorderTitle(String activityName){
        setBorder(javax.swing.BorderFactory.createTitledBorder(activityName));

    }

    /**
     * A method that sets gui objects enabled/focusable false.
     */
    public void saveActivityButtonClicked() {
        activityNameTextField.setFocusable(false);
        boundToSessionDropDown.setEnabled(false);
        startDateTextField.setFocusable(false);
        endDateTextField.setFocusable(false);
        statusDropDown.setEnabled(false);
        responsibleDropDown.setEnabled(false);
        activityDescTextArea.setFocusable(false);
        activityGoalsTextArea.setFocusable(false);
        activityPlaceTextField.setFocusable(false);
        actionListCheckBox.setFocusable(false);
        actionListCheckBox.setEnabled(false);
        saveActivityButton.setText("Rediger");
    }

    /**
     * A method that sets gui objects enabled/focusable true;
     */
    public void editActivityButtonClicked() {
        activityNameTextField.setFocusable(true);
        boundToSessionDropDown.setEnabled(true);
        startDateTextField.setFocusable(true);
        endDateTextField.setFocusable(true);
        statusDropDown.setEnabled(true);
        responsibleDropDown.setEnabled(true);
        activityDescTextArea.setFocusable(true);
        activityGoalsTextArea.setFocusable(true);
        activityPlaceTextField.setFocusable(true);
        actionListCheckBox.setEnabled(true);
        saveActivityButton.setText("Lagre");
    }

    /**
     * A method that sets the a date in the date textfields and hides the enddate textfield and sets the start date focusable false
     * @param date
     */
    public void boundToSession(String date){
        startDateTextField.setText(date);
        endDateTextField.setText(date);
        endDateTextField.setVisible(false);
        strekLabel.setVisible(false);
        startDateTextField.setFocusable(false);
    }

    /**
     * A method that shows the enddate textfield and makes the startdate focusable.
     */
    public void notBoundToSession(){
        endDateTextField.setVisible(true);
        strekLabel.setVisible(true);
        startDateTextField.setFocusable(true);
    }

    /*
     *  Getters and setters
     */

    public JLabel getActivityDescLabel() {
        return activityDescLabel;
    }

    public JTextArea getActivityDescTextArea() {
        return activityDescTextArea;
    }

    public JLabel getActivityPlaceLabel() {
        return activityPlaceLabel;
    }

    public JTextArea getActivityGoalsTextArea() {
        return activityGoalsTextArea;
    }

    public JLabel getActivityGoalsLabel() {
        return activityGoalsLabel;
    }

    public JCheckBox getActionListCheckBox() {
        return actionListCheckBox;
    }

    public JTextField getActivityPlaceTextField() {
        return activityPlaceTextField;
    }

    public DefaultComboBoxModel getActivityResponsibleModel() {
        return activityResponsibleModel;
    }

    public JComboBox getStatusDropDown() {
        return statusDropDown;
    }

    public DefaultComboBoxModel getActivityStatusModel() {
        return activityStatusModel;
    }

    public JButton getEditActivityButton() {
        return saveActivityButton;
    }

    public JTextField getEndDateTextField() {
        return endDateTextField;
    }

    public JScrollPane getjScrollPane5() {
        return jScrollPane5;
    }

    public JScrollPane getjScrollPane6() {
        return jScrollPane6;
    }

    public JComboBox getResponsibleDropDown() {
        return responsibleDropDown;
    }

    public JLabel getResponsibleLabel() {
        return responsibleLabel;
    }

    public JLabel getStartDateLabel() {
        return startDateLabel;
    }

    public JTextField getStartDateTextField() {
        return startDateTextField;
    }

    public JLabel getStatusLabel() {
        return statusLabel;
    }

    public JLabel getStrekLabel() {
        return strekLabel;
    }

    public JComboBox getBoundToSessionDropDown() {
        return boundToSessionDropDown;
    }

    public JLabel getBoundToSessionLabel() {
        return boundToSessionLabel;
    }

    public DefaultComboBoxModel getBoundToSessionModel() {
        return boundToSessionModel;
    }

    public JButton getSaveActivityButton() {
        return saveActivityButton;
    }


    public String getActivityName(){
        return activityNameTextField.getText();
    }

    public String getStartDate(){
        return startDateTextField.getText();
    }

    public String getEndDate(){
        return endDateTextField.getText();
    }

    public String getResponsible(){
        return (String) responsibleDropDown.getSelectedItem();
    }

    public String getStatus(){
        return (String) statusDropDown.getSelectedItem();
    }

    public String getDescription(){
        return activityDescTextArea.getText();
    }

    public String getGoals(){
        return activityGoalsTextArea.getText();
    }

    public String getActivityLocation(){
        return activityPlaceTextField.getText();
    }

    public JTextField getActivityNameTextField() {
        return activityNameTextField;
    }

    public boolean isOnActionList(){
        return actionListCheckBox.isSelected();
    }
  }
